package logic

import (
	"context"

	"worker/sse/internal/svc"
	"worker/sse/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendToAllLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendToAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendToAllLogic {
	return &SendToAllLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SendToAllLogic) SendToAll(req *types.SendToAllReq) (resp *types.SendToAllResp, err error) {
	resp = &types.SendToAllResp{Ok: true}
	l.svcCtx.SSE.SendToAll(req.Msg)

	return resp, nil
}
